<template>
  <div class="app-container">
    <div v-show="!show.detailShow">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
        <el-form-item label="统一社会信用代码" prop="f00Tyxydm">
          <el-input
            v-model="queryParams.f00Tyxydm"
            placeholder="请输入统一社会信用代码"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="单位详细名称" prop="f00Dwmc">
          <el-input
            v-model="queryParams.f00Dwmc"
            placeholder="请输入单位详细名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
          >新增</el-button>
        </el-col>
<!--        <el-col :span="1.5">
          <el-button
            type="success"
            plain
            icon="el-icon-edit"
            size="mini"
            :disabled="single"
            @click="handleUpdate"
            v-hasPermi="['system:mjzz:edit']"
          >修改</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['system:mjzz:remove']"
          >删除</el-button>
        </el-col>-->
        <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
          >导出</el-button>
        </el-col>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>

      <el-table v-loading="loading" :data="mjzzList" @selection-change="handleSelectionChange">
        <el-table-column
          v-for="(item,i) in tablecols"
          :label="item.label"
          :prop="item.fieldsql"
          :width="(item.label).length*25"
          show-overflow-tooltip>
        </el-table-column>
        <el-table-column fixed="right" label="操作" align="center"
                         class-name="small-padding fixed-width" width="200dp">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleDetails(scope.row)"
            >详情
            </el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
            >修改</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
    <economicComDetail v-if="show.detailShow" ref="detail" :titles="tablecols" :show="show" tableName="mjzz"></economicComDetail>
    <!-- 添加或修改【请填写功能名称】对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="70%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="20%">
        <el-form-item label="统一社会信用代码" prop="f00Tyxydm">
          <el-input v-model="form.f00Tyxydm" placeholder="请输入统一社会信用代码" />
        </el-form-item>
        <el-form-item label="单位详细名称" prop="f00Dwmc">
          <el-input v-model="form.f00Dwmc" placeholder="请输入单位详细名称" />
        </el-form-item>
        <el-form-item label="年初存货" prop="f01Ncch">
          <el-input v-model="form.f01Ncch" placeholder="请输入年初存货" />
        </el-form-item>
        <el-form-item label="流动资产合计" prop="f02Ldzchj">
          <el-input v-model="form.f02Ldzchj" placeholder="请输入流动资产合计" />
        </el-form-item>
        <el-form-item label="流动资产中存货" prop="f03Ldch">
          <el-input v-model="form.f03Ldch" placeholder="请输入流动资产中存货" />
        </el-form-item>
        <el-form-item label="长期投资" prop="f04Cqtz">
          <el-input v-model="form.f04Cqtz" placeholder="请输入长期投资" />
        </el-form-item>
        <el-form-item label="固定资产原价" prop="f05Gdzcyj">
          <el-input v-model="form.f05Gdzcyj" placeholder="请输入固定资产原价" />
        </el-form-item>
        <el-form-item label="固定资产中土地、房屋和构筑物" prop="f06Gdzctd">
          <el-input v-model="form.f06Gdzctd" placeholder="请输入固定资产中土地、房屋和构筑物" />
        </el-form-item>
        <el-form-item label="固定资产中机器设备" prop="f07Gdzcjq">
          <el-input v-model="form.f07Gdzcjq" placeholder="请输入固定资产中机器设备" />
        </el-form-item>
        <el-form-item label="固定资产中运输设备" prop="f08Gdzcys">
          <el-input v-model="form.f08Gdzcys" placeholder="请输入固定资产中运输设备" />
        </el-form-item>
        <el-form-item label="在建工程" prop="f09Zjgc">
          <el-input v-model="form.f09Zjgc" placeholder="请输入在建工程" />
        </el-form-item>
        <el-form-item label="文物文化资产" prop="f10Wxzcyj">
          <el-input v-model="form.f10Wxzcyj" placeholder="请输入文物文化资产" />
        </el-form-item>
        <el-form-item label="无形资产" prop="f11Wxzc">
          <el-input v-model="form.f11Wxzc" placeholder="请输入无形资产" />
        </el-form-item>
        <el-form-item label="资产总计" prop="f12Zczj">
          <el-input v-model="form.f12Zczj" placeholder="请输入资产总计" />
        </el-form-item>
        <el-form-item label="负债总计" prop="f13Fzzj">
          <el-input v-model="form.f13Fzzj" placeholder="请输入负债总计" />
        </el-form-item>
        <el-form-item label="净资产总计" prop="f14Jzczj">
          <el-input v-model="form.f14Jzczj" placeholder="请输入净资产总计" />
        </el-form-item>
        <el-form-item label="本年收入合计" prop="f15Bnsrhj">
          <el-input v-model="form.f15Bnsrhj" placeholder="请输入本年收入合计" />
        </el-form-item>
        <el-form-item label="捐赠收入" prop="f16Jzsr">
          <el-input v-model="form.f16Jzsr" placeholder="请输入捐赠收入" />
        </el-form-item>
        <el-form-item label="会费收入" prop="f17Hfsr">
          <el-input v-model="form.f17Hfsr" placeholder="请输入会费收入" />
        </el-form-item>
        <el-form-item label="本年费用合计" prop="f18Bnfyhj">
          <el-input v-model="form.f18Bnfyhj" placeholder="请输入本年费用合计" />
        </el-form-item>
        <el-form-item label="业务活动成本" prop="f19Ywhdcb">
          <el-input v-model="form.f19Ywhdcb" placeholder="请输入业务活动成本" />
        </el-form-item>
        <el-form-item label="业务活动人员费用" prop="f20Ryfy">
          <el-input v-model="form.f20Ryfy" placeholder="请输入业务活动人员费用" />
        </el-form-item>
        <el-form-item label="业务活动日常费用" prop="f21Rcfy">
          <el-input v-model="form.f21Rcfy" placeholder="请输入业务活动日常费用" />
        </el-form-item>
        <el-form-item label="业务活动固定资产折旧" prop="f22Ghjf">
          <el-input v-model="form.f22Ghjf" placeholder="请输入业务活动固定资产折旧" />
        </el-form-item>
        <el-form-item label="业务活动税费" prop="f23Sf">
          <el-input v-model="form.f23Sf" placeholder="请输入业务活动税费" />
        </el-form-item>
        <el-form-item label="管理费用" prop="f24Glfy">
          <el-input v-model="form.f24Glfy" placeholder="请输入管理费用" />
        </el-form-item>
        <el-form-item label="管理人员费用" prop="f25Ryfy">
          <el-input v-model="form.f25Ryfy" placeholder="请输入管理人员费用" />
        </el-form-item>
        <el-form-item label="管理日常费用" prop="f26Rcfy">
          <el-input v-model="form.f26Rcfy" placeholder="请输入管理日常费用" />
        </el-form-item>
        <el-form-item label="管理固定资产折旧" prop="f27Gdzczj">
          <el-input v-model="form.f27Gdzczj" placeholder="请输入管理固定资产折旧" />
        </el-form-item>
        <el-form-item label="管理税费" prop="f28Sf">
          <el-input v-model="form.f28Sf" placeholder="请输入管理税费" />
        </el-form-item>
        <el-form-item label="净资产变动额" prop="f29Jzcbde">
          <el-input v-model="form.f29Jzcbde" placeholder="请输入净资产变动额" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listMjzz, getMjzz, delMjzz, addMjzz, updateMjzz } from "@/api/economic/mjzz";
import { getFields } from '@/api/economic/basic'
import economicComDetail from '@/views/economic/economicComDetail'

export default {
  name: "Mjzz",
  components: {
    economicComDetail
  },
  data() {
    return {
      show:{
        detailShow:false,
      },
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      mjzzList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        f00Tyxydm: null,
        f00Dwmc: null,
        f01Ncch: null,
        f02Ldzchj: null,
        f03Ldch: null,
        f04Cqtz: null,
        f05Gdzcyj: null,
        f06Gdzctd: null,
        f07Gdzcjq: null,
        f08Gdzcys: null,
        f09Zjgc: null,
        f10Wxzcyj: null,
        f11Wxzc: null,
        f12Zczj: null,
        f13Fzzj: null,
        f14Jzczj: null,
        f15Bnsrhj: null,
        f16Jzsr: null,
        f17Hfsr: null,
        f18Bnfyhj: null,
        f19Ywhdcb: null,
        f20Ryfy: null,
        f21Rcfy: null,
        f22Ghjf: null,
        f23Sf: null,
        f24Glfy: null,
        f25Ryfy: null,
        f26Rcfy: null,
        f27Gdzczj: null,
        f28Sf: null,
        f29Jzcbde: null
      },
      tablecols:null,
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      currentPro: null//选择的某一个项目
    };
  },
  created() {
    this.getFieldCols();
  },
  methods: {
    getFieldCols(){
      let that=this;
      this.loading = true
      getFields({
        "tabel_name":"sys_econ_mjzz"
      }).then(response => {
        that.tablecols=[];
        for(let i=0;i<response.length;i++) {
          let field = response[i];
          let label = field.comment;
          if (field.comment.indexOf("(") > -1)
            label = field.comment.substr(0, field.comment.indexOf("("));

          let dbs=field.field.split("_");
          let str=null;
          if(dbs.length==2){
            str=dbs[0]+dbs[1].charAt(0).toUpperCase() + dbs[1].slice(1);
          }else{
            str=dbs[0]+dbs[1]+dbs[2].charAt(0).toUpperCase() + dbs[2].slice(1);
          }
          if(field.field=="f_x")
            str="fx";
          if(field.field=="f_y")
            str="fy";
          field.fieldsql=str;
          field.label = label;
          that.tablecols.push(field);
        }
        this.getList();
      })
    },
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      listMjzz(this.queryParams).then(response => {
        this.mjzzList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        f00Tyxydm: null,
        f00Dwmc: null,
        f01Ncch: null,
        f02Ldzchj: null,
        f03Ldch: null,
        f04Cqtz: null,
        f05Gdzcyj: null,
        f06Gdzctd: null,
        f07Gdzcjq: null,
        f08Gdzcys: null,
        f09Zjgc: null,
        f10Wxzcyj: null,
        f11Wxzc: null,
        f12Zczj: null,
        f13Fzzj: null,
        f14Jzczj: null,
        f15Bnsrhj: null,
        f16Jzsr: null,
        f17Hfsr: null,
        f18Bnfyhj: null,
        f19Ywhdcb: null,
        f20Ryfy: null,
        f21Rcfy: null,
        f22Ghjf: null,
        f23Sf: null,
        f24Glfy: null,
        f25Ryfy: null,
        f26Rcfy: null,
        f27Gdzczj: null,
        f28Sf: null,
        f29Jzcbde: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.f00Tyxydm)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加【请填写功能名称】";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const f00Tyxydm = row.f00Tyxydm || this.ids
      getMjzz(f00Tyxydm).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改【请填写功能名称】";
      });
    },
    //查看项目详情
    handleDetails(row) {
      this.show.detailShow=true;
      this.currentPro = row
      this.detailDialogOpen = true
      this.dialogTitle=row.xmmc;
      this.$nextTick(() => {
          this.$refs.detail.getCurrentProDetails(this.currentPro)
        }
      )
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.title.startsWith("修改")) {
            updateMjzz(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else if (this.title.startsWith("添加"))  {
            addMjzz(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const f00Tyxydms = row.f00Tyxydm || this.ids;
      this.$modal.confirm('是否确认删除【请填写功能名称】编号为"' + f00Tyxydms + '"的数据项？').then(function() {
        return delMjzz(f00Tyxydms);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('economic/mjzz/export', {
        ...this.queryParams
      }, `mjzz_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style scoped>
.map-hight {
  height: 85vh;
}

.ztzys {
  width: 285px;
  margin-right: 21px !important;
  display: inline-flex !important;
}

::v-deep .el-dialog__body {
  padding: 10px 10px;
}

::v-deep .el-dialog__headerbtn {
  top: 5px;
  right: 5px;
  font-size: 26px;
}

::v-deep .el-dialog__header {
  padding: 10px 0px 0px 10px;
}

::v-deep .el-date-editor.el-input, .el-date-editor.el-input__inner {
  width: 185px;
}

::v-deep .el-input__inner {
  height: 35px;
  line-height: 35px;
}

::v-deep .el-input__prefix, .el-input__suffix {
  top: -3px;
}

::v-deep .el-table--enable-row-hover .el-table__body tr:hover > td {
  background-color: rgba(173, 199, 133, 0.62) !important;
}

::v-deep .el-input__inner {
  margin-bottom: 8px
}

::v-deep .el-form-item {
  margin-bottom: 8px;
}

::v-deep .el-input {
  width: 90%;
}

::v-deep .el-form-item__label {
  line-height: 30px;
  min-width: 100px;
}

::v-deep .el-form-item__content {
  line-height: 25px;
}

::v-deep .el-form--inline .el-form-item {
  margin-right: 0px;
}

.left50 {
  margin-left: 30px;
}
</style>
